using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyState_幽魂_攻击 : EnemyStateBase_幽魂
{
	private ItemSO_Data_金池招式系数 _系数Data;

	private List<string> _List_攻击名称 = new List<string> { "龟派气功_蓄力", "双峰贯耳", "磕头", "震荡波_一段", "扫地" };

	private Coroutine _Cor_攻击;

	private int _连击次数;

	private int _Max连击次数;

	private Vector2Int _Ran连击次数 = new Vector2Int(3, 6);

	public EnemyState_幽魂_攻击()
	{
		_系数Data = MonoSingleton<MyDataManager>.Instance._Data_Enemy._Data_金池招式系数;
	}

	public override void OnEnter()
	{
		F_攻击();
	}

	public override void OnExit()
	{
		if (_Cor_攻击 != null)
		{
			_Mono.StopCoroutine(_Cor_攻击);
			_Cor_攻击 = null;
		}
		_Mono._GO_激光蓄力特效.SetActive(value: false);
		_Mono._GO_激光特效.SetActive(value: false);
	}

	public override void OnUpdate()
	{
	}

	private void F_攻击()
	{
		if (Random.value < 0.15f)
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_震荡波四连());
			return;
		}
		_连击次数 = 0;
		_Max连击次数 = Random.Range(_Ran连击次数.x, _Ran连击次数.y);
		F_连击();
	}

	private void F_连击()
	{
		int index = Random.Range(0, _List_攻击名称.Count);
		_连击次数++;
		bool 有后续 = _连击次数 < _Max连击次数;
		_Mono._Ani.Play("New State");
		if (_List_攻击名称[index] == "龟派气功_蓄力")
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_龟派气功(有后续));
		}
		else if (_List_攻击名称[index] == "双峰贯耳")
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_双峰贯耳(有后续));
		}
		else if (_List_攻击名称[index] == "扫地")
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_扫地(有后续));
		}
		else if (_List_攻击名称[index] == "磕头")
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_磕头(有后续));
		}
		else if (_List_攻击名称[index] == "震荡波_一段")
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_震荡波_一段(有后续));
		}
	}

	private void F_判断是否有后续(bool 有后续)
	{
		if (有后续)
		{
			F_连击();
		}
		else
		{
			_Mono.ChangeState(StateType_Enemy_幽魂.站立);
		}
	}

	private void F_攻击朝向和冲力(float 冲力)
	{
		Vector2 vector = _Mono.transform.position;
		Vector2 vector2 = _Mono._Tsf_玩家.position;
		bool flag = vector2.x < vector.x;
		_Mono._Rb2D.velocity = Vector2.zero;
		_Mono._Rb2D.velocity = 4f * 冲力 * (vector2 - vector).normalized;
		_Mono.transform.localScale = new Vector3(flag ? 1 : (-1), 1f, 1f);
	}

	private IEnumerator Cor_震荡波四连()
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._震荡波_四连._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._震荡波_四连._击退力度;
		_Timer = _Mono._Dict_Anis_name_time["震荡波_四连"];
		_Mono._Ani.Play("震荡波_四连");
		float time = 0f;
		while (time < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time += Time.deltaTime;
			}
			yield return null;
		}
		if (Random.value > 0.5f)
		{
			_Cor_攻击 = _Mono.StartCoroutine(Cor_龟派气功(有后续: false));
		}
		else
		{
			_Mono.ChangeState(StateType_Enemy_幽魂.站立);
		}
	}

	private IEnumerator Cor_龟派气功(bool 有后续)
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._龟派气功_释放._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._龟派气功_释放._击退力度;
		F_攻击朝向和冲力(0f);
		_Timer = Random.Range(0.3f, 2f);
		_Mono._Ani.Play("龟派气功_蓄力");
		_Mono._GO_激光蓄力特效.SetActive(value: true);
		float time2 = 0f;
		while (time2 < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time2 += Time.deltaTime;
			}
			yield return null;
		}
		_Timer = Random.Range(0.8f, 1.2f);
		_Mono._Ani.Play("龟派气功_释放");
		_Mono._GO_激光蓄力特效.SetActive(value: false);
		_Mono._GO_激光特效.SetActive(value: true);
		time2 = 0f;
		while (time2 < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time2 += Time.deltaTime;
			}
			yield return null;
		}
		_Mono._GO_激光特效.SetActive(value: false);
		F_判断是否有后续(有后续);
	}

	private IEnumerator Cor_双峰贯耳(bool 有后续)
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._双峰贯耳._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._双峰贯耳._击退力度;
		F_攻击朝向和冲力(10f);
		_Timer = _Mono._Dict_Anis_name_time["双峰贯耳"];
		_Mono._Ani.Play("双峰贯耳");
		float time = 0f;
		while (time < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time += Time.deltaTime;
			}
			yield return null;
		}
		F_判断是否有后续(有后续);
	}

	private IEnumerator Cor_扫地(bool 有后续)
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._扫地._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._扫地._击退力度;
		F_攻击朝向和冲力(10f);
		_Timer = _Mono._Dict_Anis_name_time["扫地"];
		_Mono._Ani.Play("扫地");
		float time = 0f;
		while (time < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time += Time.deltaTime;
			}
			yield return null;
		}
		F_判断是否有后续(有后续);
	}

	private IEnumerator Cor_磕头(bool 有后续)
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._磕头._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._磕头._击退力度;
		F_攻击朝向和冲力(10f);
		_Timer = _Mono._Dict_Anis_name_time["磕头"];
		_Mono._Ani.Play("磕头");
		float time = 0f;
		while (time < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time += Time.deltaTime;
			}
			yield return null;
		}
		F_判断是否有后续(有后续);
	}

	private IEnumerator Cor_震荡波_一段(bool 有后续)
	{
		yield return null;
		_Mono._C_攻击判断._伤害 = _Mono._Data._Atk * _系数Data._震荡波_一段._伤害系数;
		_Mono._C_攻击判断._击退力度 = _系数Data._震荡波_一段._击退力度;
		F_攻击朝向和冲力(0f);
		_Timer = _Mono._Dict_Anis_name_time["震荡波_一段"];
		_Mono._Ani.Play("震荡波_一段");
		float time = 0f;
		while (time < _Timer)
		{
			if (!_Mono._Is被定)
			{
				time += Time.deltaTime;
			}
			yield return null;
		}
		F_判断是否有后续(有后续);
	}
}
